package cn.dlc.com.user.service.impl;

import cn.dlc.com.user.entity.MyAccount;
import cn.dlc.com.user.mapper.UserMapper;
import cn.dlc.com.user.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 邓立川
 * @date 2021/11/28 10:53
 * @desc 当前类的描述信息
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        MyAccount account = new MyAccount();
        account.setUsername(username);

        QueryWrapper<MyAccount> queryWrapper = new QueryWrapper<>(account);

        MyAccount result = userMapper.selectOne(queryWrapper);

        UserDetails user = User.withUsername(result.getUsername())
                .password(result.getPassword())
                .authorities("p1").build();

        return user;
    }
}
